import threading

class RW_lock:
    """
    读写锁简约版: 缺点: 假设连续acquire了100次读锁, 则写操作需阻塞到这100次读全部结束了才行
    """
    def __init__(self):
        self._lock = threading.Lock()
        self._rlock = threading.Lock()
        self.read_num = 0

    def release_Rlock():
        with self._rlock:
            self.read_num -= 1
            if self.read_num == 0:
                self._lock.release()

    def acquire_Rlock():
        with self._rlock:
            self.read_num += 1
            if read_num == 1:
                self._lock.acquire()

    def release_Wlock():
        self._lock.release()
    
    def acquire_Wlock():
        self._lock.acquire()

    
